

void UI_ImageOptionsDialog::init() {
    graphicSize = PF_Vector(0.0,0.0);
    updateEnabled = true;
    
    PF_SETTINGS->beginGroup("/ExportImage");
    leWidth->setText(PF_SETTINGS->readEntry("/Width", "640"));
    leHeight->setText(PF_SETTINGS->readEntry("/Height", "480"));
    if (PF_SETTINGS->readEntry("/BlackBackground", "0")=="1") {
        rbBlack->setChecked(true);
    }
    /*if (PF_SETTINGS->readEntry("/Blackwhite", "0")=="1") {
        rbBlackwhite->setChecked(true);
    }*/
    PF_SETTINGS->endGroup();
}

void UI_ImageOptionsDialog::setGraphicSize(const PF_Vector& s) {
    graphicSize = s;
}

void UI_ImageOptionsDialog::ok() {
    PF_SETTINGS->beginGroup("/ExportImage");
    PF_SETTINGS->writeEntry("/Width", leWidth->text());
    PF_SETTINGS->writeEntry("/Height", leHeight->text());
    PF_SETTINGS->writeEntry("/BlackBackground", (int)rbBlack->isChecked());
    //PF_SETTINGS->writeEntry("/Blackwhite", (int)rbBlackwhite->isChecked());
    PF_SETTINGS->endGroup();
    
    accept();
}

void UI_ImageOptionsDialog::sizeChanged() {
    if (updateEnabled) {
    updateEnabled = false;
    cbResolution->setCurrentText("auto");
    updateEnabled = true;
    }
}

void  UI_ImageOptionsDialog::resolutionChanged() {
    if (updateEnabled) {
    updateEnabled = false;
    bool ok = false;
    double res = PF_Math::eval(cbResolution->currentText(), &ok);
    if (!ok) {
        res = 1.0;
    }
    int w = PF_Math::round(res * graphicSize.x);
    int h = PF_Math::round(res * graphicSize.y);
    leWidth->setText(QString("%1").arg(w));
    leHeight->setText(QString("%1").arg(h));
    updateEnabled = true;
    }
}

QSize UI_ImageOptionsDialog::getSize() {
    return QSize(PF_Math::round(PF_Math::eval(leWidth->text())), 
                 PF_Math::round(PF_Math::eval(leHeight->text())));
}

bool UI_ImageOptionsDialog::isBackgroundBlack() {
    return rbBlack->isChecked();
}

/*bool UI_ImageOptionsDialog::isBlackwhite() {
    return rbBlackwhite->isChecked();
}*/
